// Package authserver
// Create  2023-04-05 22:01:17
package authserver

import (
	"context"
	"time"

	"gitee.com/zhenxinma/gorpc/pkg/client"

	"gitee.com/zhenxinma/gocommon/pkg/xserver/authserver"
)

var authServerImplInstance *AuthServerImpl

type AuthServerImpl struct {
}

func GetAuthServerImplInstance() *AuthServerImpl {
	if authServerImplInstance != nil {
		return authServerImplInstance
	}
	authServerImplInstance = &AuthServerImpl{}
	return authServerImplInstance
}

func (a *AuthServerImpl) GetServerName() string {
	return "AuthServer"
}

// GetAuthInfo 获取鉴权信息.
func (a *AuthServerImpl) GetAuthInfo(c context.Context, arg *authserver.AuthArgs, rsp *authserver.AuthResponse) error {
	cli, err := client.NewClient("tcp", ":18888", &client.OptionConfig{
		ServerTimeout: 1 * time.Hour,
		ClientTimeout: 1 * time.Hour,
	})
	if err != nil {
		return err
	}
	return cli.Call(c, a.GetServerName(), "GetAuthInfo", arg, rsp)
}
